#ifndef __W25QXX_H__
#define __W25QXX_H__

#include <stdint.h>


#define  W25QXX_CMD_WRITE        0x02  /* Write to Memory instruction */
#define  W25QXX_CMD_WRSR         0x01  /* Write Status Register instruction */
#define  W25QXX_CMD_WREN         0x06  /* Write enable instruction */
#define  W25QXX_CMD_READ         0x03  /* Read from Memory instruction */
#define  W25QXX_CMD_RDSR         0x05  /* Read Status Register instruction  */
#define  W25QXX_CMD_RDID         0x9F  /* Read identification */
#define  W25QXX_CMD_SE           0x20  /* Sector Erase instruction */
#define  W25QXX_CMD_BE           0xC7  /* Bulk Erase instruction */
#define  W25QXX_WIP_FLAG         0x01  /* Write In Progress (WIP) flag */
#define  W25QXX_DUMMY_BYTE       0xA5

#define  W25QXX_PAGE_SIZE        256
#define  W25QXX_SECTOR_SIZE      4096


#define  W25Q16_ID               0xEF4015
#define  W25Q32_ID               0xEF4016
#define  W25Q64_ID               0xEF4017
#define  W25Q128_ID              0xEF4018
#define  W25Q256_ID              0xEF4019
#define  W25Q512_ID              0xEF401A


typedef enum __W25QXX_Model_t
{
  W25QXX_MODEL_ERROR     = 0,
  W25QXX_MODEL_W25Q16    = 1,
  W25QXX_MODEL_W25Q32    = 2,
  W25QXX_MODEL_W25Q64    = 3,
  W25QXX_MODEL_W25Q128   = 4,
  W25QXX_MODEL_W25Q256   = 5,
  W25QXX_MODEL_W25Q512   = 6,
} W25QXX_Model_t;


/*--------------------------------- 函数声明 ---------------------------------------*/
W25QXX_Model_t W25QXX_Device_Init(void);
void W25QXX_EraseSector(uint32_t SectorAddr);	
void W25QXX_EraseBulk(void);							
void W25QXX_WritePage(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite);		
void W25QXX_WriteBuffer(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite);
void W25QXX_ReadBuffer(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t NumByteToRead);
uint32_t W25QXX_ReadID(void);
void W25QXX_WriteEnable(void);
void W25QXX_WaitForWriteEnd(void);


#endif


